package com.liuyang.concurrency.chapter1;

public class TryConcurrency {

    public static void main(String[] args) {
        new Thread("READ-THREAD"){
            @Override
            public void run(){
                writeDataToFile();
            }
        }.start();
        new Thread("WRITE-THREAD"){
            @Override
            public void run(){
                writeDataToFile();
            }
        }.start();
    }

    private static void readFromDataBase(){
        //read data from database and handle it
        try {
            println("begin read data from db");
            Thread.sleep(1000*10L);
            println("Read data done and start handle it");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        println("The data handle finish and successfully");
    }

    private static void writeDataToFile(){
        try {
            println("begin write data from db");
            Thread.sleep(1000*10L);
            println("Write data done and start handle it");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        println("The Write data handle finish and successfully");
    }

    private static void println(String message){
        System.out.println(message);
    }

}
